package com.init.config;

import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;

//@Configuration
//@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http
            .authorizeRequests()
                .antMatchers("/", "/home").permitAll() // 允许所有用户访问根路径和home路径
                .anyRequest().authenticated() // 其他路径需要认证
                .and()
            .formLogin()
                .loginPage("/login") // 登录页面
                .permitAll()
                .and()
            .logout()
                .permitAll();
    }
}
